//
//  YTDisNewsVC.m
//  CllForIOS
//
//  Created by qiyun on 2018/3/30.
//  Copyright © 2018年 aRui. All rights reserved.
//

#import "YTDisNewsVC.h"
#import "YTDisNoticeCell.h"
#import "YTWebViewVC.h"
@interface YTDisNewsVC ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong) UITableView * tableView;
@property (nonatomic, strong) NSArray * titleArray;
@end

@implementation YTDisNewsVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setNav];
    self.view.backgroundColor=RGBA(236, 236, 236);
    self.tableView.backgroundColor=[UIColor whiteColor];
    [self loaddata];
    
}
-(void)setNav{
    self.titleLabel.text=@"资讯";
    self.lineView.hidden=YES;
    [self.leftimaBtn setImage:IMAGE(@"Mine_back") forState:UIControlStateNormal];
    
}
-(void)loaddata{
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    [SendRequest getinfoDetailWithURL:k_NewsUrl(k_User_News) withDictionary:nil result:^(NSDictionary *result, NSError *error) {
        if (result[@"data"]) {
            self.titleArray=result[@"data"];
            dispatch_group_notify(dispatch_group_create(), dispatch_get_main_queue(), ^{
                [self.tableView reloadData];
            });
        }
    [MBProgressHUD hideAllHUDsForView:self.view animated:YES];
    }];
}

- (UITableView *)tableView{
    if (!_tableView) {
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, k_statusbarHeight+49+12, SCREEN_W, SCREEN_H-k_statusbarHeight-49) style:UITableViewStylePlain];
        _tableView.separatorColor = RGBA(223, 223, 223);
        _tableView.separatorInset = UIEdgeInsetsMake(0, 12, 0, 12);
        _tableView.scrollEnabled=YES;
        _tableView.delegate = self;
        _tableView.dataSource = self;
        [self.view addSubview:_tableView];
        _tableView.tableFooterView = [UIView new];
        [_tableView registerClass:[YTDisNoticeCell class] forCellReuseIdentifier:@"YTDisNoticeCell"];
        
        if ([_tableView respondsToSelector:@selector(setContentInsetAdjustmentBehavior:)]) {
            _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
        }
    }
    return _tableView;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return  self.titleArray.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 0.0001f;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0.0001f;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return AfW(51);
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString * cellId = @"YTDisNoticeCell";
    YTDisNoticeCell * cell = [tableView dequeueReusableCellWithIdentifier:cellId forIndexPath:indexPath];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    NSString*desstr=self.titleArray[indexPath.row][@"shortTitle"];
    cell.deslabel.text=desstr;
    if (indexPath.row==0) {
        cell.hotlabel.hidden=NO;
        cell.circleimg.hidden=YES;
    }

    return cell;

}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    YTWebViewVC*vc=[[YTWebViewVC alloc]init];
    vc.urlStr=[NSString stringWithFormat:@"https://m.qyun88.com/find/findList_message.html?id=%@",self.titleArray[indexPath.row][@"id"]];
    [self.navigationController pushViewController:vc animated:1];
}
@end
